<?php defined('SYSPATH') OR die('No direct access allowed.');

class Category_Controller extends Viewbase_Controller{
	
	public function __construct(){
		
		$this->modelname='category';	
		$this->controllername='category';
		$this->orderby=array('title'=>'');
		$this->parent_column='parent_id';
		$this->forms=array(array('title'=>'Input', 'link'=>'input'), array('title'=>'Action', 'link'=>'action'));
		parent::__construct();	
	}
	
	public function __postprocess_model($model){
		
		if($this->input->post('formtype')=='multiple'){
			$model->delete();
		
			foreach($this->input->post('titlearray') as $title){
				if($title!=""){
					$model=ORM::factory('category');
					$model=$this->__post_to_model($model);
					$model->title=$title;
					$model->save();
				}
			}
		}
	}	
}